function getUrlParam(name) {//
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}
var cph = '',streetNo = '',orderNo = '',openid='';
var arr =[];
$(function(){
	openid = localStorage.getItem("openid");
	orderNo = getUrlParam('orderNo');
	$.ajax({
		url: '/park/data/getUserInfo?openid='+openid,
		type: 'post',
		dataType: 'json',
		success: function(res) {
			if(res.data!=null){
				cph = res.data.cph;
				streetNo = res.data.streetNo;
				$.ajax({
					url:'/park/data/getCouponListAble',
					data:'cph='+cph+'&parkNo='+streetNo,
					type:'post',
					dataType:'json',
					success:function(res){
						if(res.code=='200'){
							new Vue({
								el:'body',
								data:{
									datas:res.data
								}
							})
							arr = res.data;
							$('#couponid').show();
						}else{
							layer.open({
								content : '没有可用的优惠券！',
								skin : 'msg',
								time : 2
							//2秒后自动关闭
							});
						}
					}
				})
			}else{
				layer.open({
					content : '未绑定有效的车牌号！',
					skin : 'msg',
					time : 2
				//2秒后自动关闭
				});
			}
		}
	})
})

function selectCoupon(_e){
	var _id = $(_e).attr('id');
	var obj = {};
	for(var i in arr){
		if(arr[i].couponId==_id){
			obj = arr[i];
			obj.status = 1;
			$('#c_'+arr[i].couponId).css('background-color','red');
			$('#type_'+arr[i].couponId).css('color','red');
		}
	}
	if(obj.couponInde=='1'){
		for(var j in arr){
			if(arr[j].couponType==obj.couponType&&arr[j].couponId!=_id){
				$('#c_'+arr[j].couponId).css('background-color','#777');
				$('#type_'+arr[j].couponId).css('color','#555');
				arr[j].status = 0;
			}
		}
	}
	if(obj.couponInde=='0'){
		for(var j in arr){
			if(arr[j].couponType==obj.couponType&&arr[j].couponInde=='1'&&arr[j].couponId!=_id){
				$('#c_'+arr[j].couponId).css('background-color','#777');
				$('#type_'+arr[j].couponId).css('color','#555');
				arr[j].status = 0;
			}
		}
	}
	if(obj.couponUnInde=='1'){
		for(var j in arr){
			if(arr[j].couponType!=obj.couponType&&arr[j].couponId!=_id){
				$('#c_'+arr[j].couponId).css('background-color','#777');
				$('#type_'+arr[j].couponId).css('color','#555');
				arr[j].status = 0;
			}
		}
	}
	if(obj.couponUnInde=='0'){
		for(var j in arr){
			if(arr[j].couponType!=obj.couponType&&arr[j].couponUnInde=='1'&&arr[j].couponId!=_id){
				$('#c_'+arr[j].couponId).css('background-color','#777');
				$('#type_'+arr[j].couponId).css('color','#555');
				arr[j].status = 0;
			}
		}
	}
}
var _couponMoney = 0.00;
var _couponNum = 0;
var _couponArr = '';
function _back(){
	for(var i in arr){
		if(arr[i].status!=null&&arr[i].status==1){
			_couponNum++;
			_couponArr+=arr[i].couponId+'_';
			_couponMoney+= parseFloat(arr[i].couponMoney);
		}
	}
	localStorage.setItem("_couponNum",_couponNum);
	localStorage.setItem("_couponArr",_couponArr);
	localStorage.setItem("_couponMoney",_couponMoney);
	location.href = '/park/index?couponType=1&orderNo='+orderNo;
}